﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Yunchang;

public class LambdaObject<T0> : ILambdaObject
{
    private T0 t0;
    private Action<T0> action;
    public void Init(T0 t0, Action<T0> action)
    {
        this.t0 = t0;
        this.action = action;
    }

    public void Execute()
    {
        if (action != null)
            action(t0);
    }
    public void OnGet() { }
    public void OnRelease()
    {
        t0 = default(T0);
        action = null;
    }
}

public class LambdaObject<T0,T1> : ILambdaObject
{
    private T0 t0;
    private T1 t1;
    private Action<T0, T1> action;
    public void Init(T0 t0,T1 t1, Action<T0, T1> action)
    {
        this.t1 = t1;
        this.t0 = t0;
        this.action = action;
    }

    public void Execute()
    {
        if (action != null)
            action(t0,t1);
    }
    public void Execute(T0 t0) {
        this.t0 = t0;
        if (action != null)
            action(t0, t1);
    }
    public void Execute(T1 t1) {
        this.t1 = t1;
        if (action != null)
        {
            action(t0,t1);
        }
    }
    public void Execute(T0 t0,T1 t1)
    {
        this.t0 = t0;
        this.t1 = t1;
        if (action != null)
        {
            action(t0, t1);
        }
    }
    public void OnGet() { }
    public void OnRelease()
    {
        t0 = default(T0);
        t1 = default(T1);
        action = null;
    }
}
